import random
import requests
import json
import re

# 这个类以后要扩展很多接口
class JDSpider():
    def spider_comment(self, id, page):
        """爬评论"""
        # try:
        HEADERS = [
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
            'Mozilla/5.0 (Windows;U;WindowsNT6.1;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10.6;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Windows NT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
            'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Macintosh;U;IntelMacOSX10_6_8;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.27 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/601.1.27',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
        ]
        # url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'
        if page == 0:
            url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'
        else:
            url = f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId={id}&score=3&sortType=6&page={page}0&pageSize=10&isShadowSku=0&fold=1'
        try:
            print(url)
            headers = {
                'Accept': '*/*',
                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
                'User-Agent': random.choice(HEADERS),
                'Connection': 'keep-alive',
                'Host': 'club.jd.com',
            }
            # print(url)
            html = requests.get(url=url, headers=headers)

            mianheaders = {
                'Accept': '*/*',
                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
                'User-Agent': random.choice(HEADERS),
                'Connection': 'keep-alive',
                'Host': 'item.jd.com',
            }
            mainHtml = requests.get(url="https://item.jd.com/6543456.html",headers=mianheaders)
            print(mainHtml.text)
            import re

            pattern = re.compile(r'\d+')  # 查找数字
            result1 = pattern.findall('runoob 123 google 456')
            result2 = pattern.findall('run88oob123google456', 0, 10)

            print(result1)
            print(result2)
            # 去掉多余得到json格式
            content = html.text.strip('fetchJSON_comment98vv995();')
            content = content.strip('fetchJSON_comment98vv37();')
            json_flag = json.loads(content, strict=False)  # 收到的str内容进行清洗处理，变成可用的json，处理好了

            print('jdmain运行成功（京东爬虫主程序）')
            JSONlist = json_flag["comments"]
            if JSONlist == []:
                print('JDSpider评论为空')
                return [], [], '😅JDSpider爬虫评论为空'
            commentList = []
            imgList = []

            for num in range(0, len(JSONlist) - 1):
                if 'content' in JSONlist[num] and len(commentList) < 150000:  # 若存在内容，并且内容条数少于4条
                    if len(JSONlist[num]['content']) <= 300 and len(JSONlist[num]['content']) >= 8:  # 控制字符150以内
                        if '此用户未填写评' in JSONlist[num]['content'] \
                                or '垃圾' in JSONlist[num]['content'] \
                                or '不要买' in JSONlist[num]['content'] \
                                or '差评' in JSONlist[num]['content'] \
                                or '坏了' in JSONlist[num]['content'] \
                                or '刷' in JSONlist[num]['content'] \
                                or '评论' in JSONlist[num]['content'] \
                                or '别买' in JSONlist[num]['content'] \
                                or '后悔' in JSONlist[num]['content'] \
                                or '真烂' in JSONlist[num]['content'] \
                                or '寒心' in JSONlist[num]['content'] \
                                or '辣鸡' in JSONlist[num]['content'] \
                                or '差' in JSONlist[num]['content'] \
                                or '差' in JSONlist[num]['content'] \
                                or '慎重买' in JSONlist[num]['content'] \
                                or '投诉' in JSONlist[num]['content'] \
                                or '退货' in JSONlist[num]['content'] \
                                or '有缺陷' in JSONlist[num]['content'] \
                                or '不负责任' in JSONlist[num]['content'] \
                                or '**' in JSONlist[num]['content'] \
                                :
                            print('忽略内容--------------------------------------------')
                            pass
                        else:
                            commentList.append(JSONlist[num]['content'].replace('\n', '').replace('\r', ''))
                    else:
                        continue
            for num in range(0, len(JSONlist) - 1):
                if 'images' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
                    for imgNum in range(0, len(JSONlist[num]['images'])):
                        if 'imgUrl' in JSONlist[num]['images'][imgNum]:  # 控制字符150以内
                            this_imgUrl = JSONlist[num]['images'][imgNum]['imgUrl']
                            # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
                            if 'img30.360buyimg.com/n0/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
                                                                  "img30.360buyimg.com/n1/")
                            if 's128x96_jfs/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
                            if '\n' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\n', '')
                            if '\r' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\r', '')
                            # if '//' in this_imgUrl:
                            #     this_imgUrl = this_imgUrl.replace("//", "")
                            imgList.append(this_imgUrl)
                            del this_imgUrl  # 销毁变量
                        else:
                            continue
                if 'afterImages' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
                    print(JSONlist[num]['afterImages'])
                    for imgNum in range(0, len(JSONlist[num]['afterImages'])):
                        print(JSONlist[num]['afterImages'][imgNum])
                        if 'imgUrl' in JSONlist[num]['afterImages'][imgNum]:  # 控制字符150以内
                            this_imgUrl = JSONlist[num]['afterImages'][imgNum]['imgUrl']
                            print(JSONlist[num]['afterImages'][imgNum]['imgUrl'])
                            # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
                            if 'img30.360buyimg.com/n0/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
                                                                  "img30.360buyimg.com/n1/")
                            if 's128x96_jfs/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
                            if '\n' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\n', '')
                            if '\r' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\r', '')
                            # if '//' in this_imgUrl:
                            #     this_imgUrl = this_imgUrl.replace("//", "")
                            imgList.append(this_imgUrl)
                            del this_imgUrl  # 销毁变量
                        else:
                            continue
                else:
                    continue

            print(f'京东爬虫程序结束,获取评论{len(commentList)}条，图片{len(imgList)}条')
            # print(imgList)


            random.shuffle(commentList)
            random.shuffle(imgList)
            # print(imgList)

            del content,json_flag,JSONlist
            return commentList, imgList, '😆jdmain转换正常'  # 打乱重拍
        except Exception as e:
            return [], [], '😅jdmain转换出错'
    def spider_Newcomment(self, id, page):

        """爬最新的评论"""
        # try:
        HEADERS = [
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
            'Mozilla/5.0 (Windows;U;WindowsNT6.1;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10.6;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Windows NT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
            'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Macintosh;U;IntelMacOSX10_6_8;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.27 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/601.1.27',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
        ]
        # url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'
        if page == 0:
            # url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'
            url = f'https://club.jd.com/comment/skuProductPageComments.action?callback=fetchJSON_comment98&productId={id}&score=0&sortType=6&page={page}&pageSize=10&isShadowSku=0&rid=0&fold=1'
        else:
            url = f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId={id}&score=3&sortType=6&page={page}0&pageSize=10&isShadowSku=0&fold=1'
            url = f'https://club.jd.com/comment/skuProductPageComments.action?callback=fetchJSON_comment98&productId={id}&score=0&sortType=6&page={page}&pageSize=10&isShadowSku=0&rid=0&fold=1'
        try:
            # print(url)
            headers = {
                'Accept': '*/*',
                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
                'User-Agent': random.choice(HEADERS),
                'Connection': 'keep-alive',
                'Host': 'club.jd.com',
            }
            # print(url)
            html = requests.get(url=url, headers=headers)

            mianheaders = {
                'Accept': '*/*',
                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
                'User-Agent': random.choice(HEADERS),
                'Connection': 'keep-alive',
                'Host': 'item.jd.com',
            }
            mainHtml = requests.get(url="https://item.jd.com/6543456.html",headers=mianheaders)
            # print(mainHtml.text)
            import re

            pattern = re.compile(r'\d+')  # 查找数字
            result1 = pattern.findall('runoob 123 google 456')
            result2 = pattern.findall('run88oob123google456', 0, 10)

            # print(result1)
            # print(result2)
            # 去掉多余得到json格式
            content = html.text.strip('fetchJSON_comment98vv995();')
            content = content.strip('fetchJSON_comment98vv37();')
            json_flag = json.loads(content, strict=False)  # 收到的str内容进行清洗处理，变成可用的json，处理好了

            print('jdmain运行成功（京东爬虫主程序）')
            JSONlist = json_flag["comments"]
            if JSONlist == []:
                # print('JDSpider评论为空')
                return [], [], '😅JDSpider爬虫评论为空'
            commentList = []
            imgList = []

            for num in range(0, len(JSONlist) - 1):
                if 'content' in JSONlist[num] and len(commentList) < 150000:  # 若存在内容，并且内容条数少于4条
                    if len(JSONlist[num]['content']) <= 300 and len(JSONlist[num]['content']) >= 50 and (JSONlist[num]['score']==5):  # 控制字符150以内
                        if '此用户未填写评' in JSONlist[num]['content'] \
                                or '垃圾' in JSONlist[num]['content'] \
                                or '不要买' in JSONlist[num]['content'] \
                                or '差评' in JSONlist[num]['content'] \
                                or '坏了' in JSONlist[num]['content'] \
                                or '刷' in JSONlist[num]['content'] \
                                or '评论' in JSONlist[num]['content'] \
                                or '别买' in JSONlist[num]['content'] \
                                or '后悔' in JSONlist[num]['content'] \
                                or '真烂' in JSONlist[num]['content'] \
                                or '寒心' in JSONlist[num]['content'] \
                                or '辣鸡' in JSONlist[num]['content'] \
                                or '差' in JSONlist[num]['content'] \
                                or '差' in JSONlist[num]['content'] \
                                or '慎重买' in JSONlist[num]['content'] \
                                or '投诉' in JSONlist[num]['content'] \
                                or '退货' in JSONlist[num]['content'] \
                                or '有缺陷' in JSONlist[num]['content'] \
                                or '不负责任' in JSONlist[num]['content'] \
                                or '**' in JSONlist[num]['content'] \
                                :
                            # print('忽略内容--------------------------------------------')
                            pass
                        else:
                            commentList.append(JSONlist[num]['content'].replace('\n', '').replace('\r', '').replace('京东','京東'))
                    else:
                        continue
            for num in range(0, len(JSONlist) - 1):
                if 'images' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
                    for imgNum in range(0, len(JSONlist[num]['images'])):
                        if 'imgUrl' in JSONlist[num]['images'][imgNum]:  # 控制字符150以内
                            this_imgUrl = JSONlist[num]['images'][imgNum]['imgUrl']
                            # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
                            if 'img30.360buyimg.com/n0/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
                                                                  "img30.360buyimg.com/n1/")
                            if 's128x96_jfs/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
                            if '\n' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\n', '')
                            if '\r' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\r', '')
                            # if '//' in this_imgUrl:
                            #     this_imgUrl = this_imgUrl.replace("//", "")
                            imgList.append(this_imgUrl)
                            del this_imgUrl  # 销毁变量
                        else:
                            continue
                if 'afterImages' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
                    # print(JSONlist[num]['afterImages'])
                    for imgNum in range(0, len(JSONlist[num]['afterImages'])):
                        # print(JSONlist[num]['afterImages'][imgNum])
                        if 'imgUrl' in JSONlist[num]['afterImages'][imgNum]:  # 控制字符150以内
                            this_imgUrl = JSONlist[num]['afterImages'][imgNum]['imgUrl']
                            # print(JSONlist[num]['afterImages'][imgNum]['imgUrl'])
                            # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
                            if 'img30.360buyimg.com/n0/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
                                                                  "img30.360buyimg.com/n1/")
                            if 's128x96_jfs/' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
                            if '\n' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\n', '')
                            if '\r' in this_imgUrl:
                                this_imgUrl = this_imgUrl.replace('\r', '')
                            # if '//' in this_imgUrl:
                            #     this_imgUrl = this_imgUrl.replace("//", "")
                            imgList.append(this_imgUrl)
                            del this_imgUrl  # 销毁变量
                        else:
                            continue
                else:
                    continue

            # print(f'京东爬虫程序结束,获取评论{len(commentList)}条，图片{len(imgList)}条')
            # print(imgList)


            random.shuffle(commentList)
            random.shuffle(imgList)
            # print(imgList)

            del content,json_flag,JSONlist
            return commentList, imgList, '😆jdmain转换正常'  # 打乱重拍
        except Exception as e:
            return [], [], '😅jdmain转换出错'

    def spider_itemData(self, id):
        """爬评论"""
        # try:
        HEADERS = [
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
            'Mozilla/5.0 (Windows;U;WindowsNT6.1;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10.6;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Windows NT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
            'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Macintosh;U;IntelMacOSX10_6_8;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.27 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/601.1.27',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
        ]


        headers = {
            'Accept': '*/*',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'User-Agent': random.choice(HEADERS),
            'Connection': 'keep-alive',
            'Host': 'item.jd.com',
        }
        mainHtml = requests.get(url=f"https://item.jd.com/{id}.html", headers=headers)
        # print(mainHtml.text)

        pattern = re.compile(r"<li title='(.*)'>(.*)：(.*)</li>")  # 查找数字
        itemDataList = pattern.findall(mainHtml.text)

        return itemDataList

    def spider_itemQueston(self,id):
        """爬产品问答"""
        # try:
        HEADERS = [
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
            'Mozilla/5.0 (Windows;U;WindowsNT6.1;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10.6;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Windows NT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
            'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Macintosh;U;IntelMacOSX10_6_8;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.27 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/601.1.27',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
        ]

        headers = {
            'Accept': '*/*',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'User-Agent': random.choice(HEADERS),
            'Connection': 'keep-alive',
            'Host': 'question.jd.com',
            'Content-Type': 'application/json'
        }

        # 请求示例 https://question.jd.com/question/getQuestionAnswerList.action?callback=jQuery8364807&page=2&productId=100008631911
        mainHtml = requests.get(
            url=f"https://question.jd.com/question/getQuestionAnswerList.action?callback=jQuery8364807&page=2&productId={id}",
            headers=headers)
        questionList = json.loads(mainHtml.text[14:-2])['questionList']

        askList = []  # 做一个渲染列表给json前段渲染
        for ask in questionList:
            askJSONG = {}
            # print(ask['content'])  这个是问题
            askJSONG["QUESTION"] = ask['content']
            KEYSList = []
            for keys in ask['answerList']:
                # print(keys['content'])  这个是两个回答
                KEYSList.append(keys['content'])
            askJSONG['KEYS'] = KEYSList
            askList.append(askJSONG)

        """[{'QUESTION': '亲们收到的暖风机噪音大吗？有没有60分贝？', 'KEYS': ['刚开始声音小，后来越来越吵了', '噪音很小']}, {'QUESTION': '这个晚上用声音大吗？', 'KEYS': ['不大，挺好的', '声音是有点的，但能接受范围']}, {'QUESTION': '请问制热后有没有难闻的塑料味？？？', 'KEYS': ['没有', '没有']}, {'QUESTION': '风量大吗', 'KEYS': ['风不大，吹个一米多吧', '近距离很好']}, {'QUESTION': '可以遥控开关吗', 'KEYS': ['不可以。可以定时', '有2种款式选择   带遥控的贵点']}, {'QUESTION': '杂音和声音大不？买过的小伙伴们', 'KEYS': ['没啥杂音，不适合房间大的', '不会，加热特别快，好用']}, {'QUESTION': '我买的这款有没有遥控器？', 'KEYS': ['没有', '没有']}, {'QUESTION': '有声音吗？', 'KEYS': ['声音比较小，接受范围内，不影响', '还挺安静的']}, {'QUESTION': '请问防水吗', 'KEYS': ['没试过，尽量避免水吧。', 'IPX0防水等级，比较差，但放在浴室有点水汽问题不大，不要把谁溅到上面']}, {'QUESTION': '有小宝宝安全吗？', 'KEYS': ['相当安全', '就是买来给小宝宝换尿不湿用的']}]"""
        # print(askList)
        return askList

    def spider_commentWWWW(self, id, page):
        """爬评论"""
        # try:
        HEADERS = [
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
            'Mozilla/5.0 (Windows;U;WindowsNT6.1;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10.6;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Windows NT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
            'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Macintosh;U;IntelMacOSX10_6_8;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.27 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/601.1.27',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
        ]
        # url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'
        if page == 0:
            url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'
        else:
            url = f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId={id}&score=3&sortType=6&page={page}0&pageSize=10&isShadowSku=0&fold=1'
        headers = {
            'Accept': '*/*',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'User-Agent': random.choice(HEADERS),
            'Connection': 'keep-alive',
            'Host': 'club.jd.com',
        }
        print(url)
        html = requests.get(url=url, headers=headers)

        # 去掉多余得到json格式
        content = html.text.strip('fetchJSON_comment98vv995();')
        content = content.strip('fetchJSON_comment98vv37();')
        json_flag = json.loads(content, strict=False)  # 收到的str内容进行清洗处理，变成可用的json，处理好了

        print('jdmain运行成功（京东爬虫主程序）')
        JSONlist = json_flag["comments"]
        if JSONlist == []:
            print('JDSpider评论为空')
            return [], [], '😅JDSpider爬虫评论为空'
        commentList = []
        imgList = []

        for num in range(0, len(JSONlist) - 1):
            if 'content' in JSONlist[num] and len(commentList) < 150000:  # 若存在内容，并且内容条数少于4条
                if len(JSONlist[num]['content']) <= 300 and len(JSONlist[num]['content']) >= 8:  # 控制字符150以内
                    if '此用户未填写评' in JSONlist[num]['content'] \
                            or '垃圾' in JSONlist[num]['content'] \
                            or '不要买' in JSONlist[num]['content'] \
                            or '差评' in JSONlist[num]['content'] \
                            or '坏了' in JSONlist[num]['content'] \
                            or '刷' in JSONlist[num]['content'] \
                            or '评论' in JSONlist[num]['content'] \
                            or '别买' in JSONlist[num]['content'] \
                            or '后悔' in JSONlist[num]['content'] \
                            or '真烂' in JSONlist[num]['content'] \
                            or '寒心' in JSONlist[num]['content'] \
                            or '辣鸡' in JSONlist[num]['content'] \
                            or '差' in JSONlist[num]['content'] \
                            or '差' in JSONlist[num]['content'] \
                            or '慎重买' in JSONlist[num]['content'] \
                            or '投诉' in JSONlist[num]['content'] \
                            or '退货' in JSONlist[num]['content'] \
                            or '有缺陷' in JSONlist[num]['content'] \
                            or '不负责任' in JSONlist[num]['content'] \
                            or '**' in JSONlist[num]['content'] \
                            :
                        print('忽略内容--------------------------------------------')
                        pass
                    else:
                        commentList.append(JSONlist[num]['content'].replace('\n', '').replace('\r', ''))
                else:
                    continue
        for num in range(0, len(JSONlist) - 1):
            if 'images' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
                for imgNum in range(0, len(JSONlist[num]['images'])):
                    if 'imgUrl' in JSONlist[num]['images'][imgNum]:  # 控制字符150以内
                        this_imgUrl = JSONlist[num]['images'][imgNum]['imgUrl']
                        # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
                        if 'img30.360buyimg.com/n0/' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
                                                              "img30.360buyimg.com/n1/")
                        if 's128x96_jfs/' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
                        if '\n' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace('\n', '')
                        if '\r' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace('\r', '')
                        # if '//' in this_imgUrl:
                        #     this_imgUrl = this_imgUrl.replace("//", "")
                        imgList.append(this_imgUrl)
                        del this_imgUrl  # 销毁变量
                    else:
                        continue
            if 'afterImages' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
                print(JSONlist[num]['afterImages'])
                for imgNum in range(0, len(JSONlist[num]['afterImages'])):
                    print(JSONlist[num]['afterImages'][imgNum])
                    if 'imgUrl' in JSONlist[num]['afterImages'][imgNum]:  # 控制字符150以内
                        this_imgUrl = JSONlist[num]['afterImages'][imgNum]['imgUrl']
                        print(JSONlist[num]['afterImages'][imgNum]['imgUrl'])
                        # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
                        if 'img30.360buyimg.com/n0/' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
                                                              "img30.360buyimg.com/n1/")
                        if 's128x96_jfs/' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
                        if '\n' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace('\n', '')
                        if '\r' in this_imgUrl:
                            this_imgUrl = this_imgUrl.replace('\r', '')
                        # if '//' in this_imgUrl:
                        #     this_imgUrl = this_imgUrl.replace("//", "")
                        imgList.append(this_imgUrl)
                        del this_imgUrl  # 销毁变量
                    else:
                        continue
            else:
                continue

        print(f'京东爬虫程序结束,获取评论{len(commentList)}条，图片{len(imgList)}条')
        # print(imgList)
        random.shuffle(commentList)
        random.shuffle(imgList)
        # print(imgList)
        return commentList, imgList, '😆jdmain转换正常'  # 打乱重拍
        # except Exception as e:
        #     return [], [], '😅jdmain转换出错'

# 这个类以后要扩展很多接口
class TBSpider():
    def spider_comment(self, id, page):
        """爬评论"""
        # try:
        HEADERS = [
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
            'Mozilla/5.0 (Windows;U;WindowsNT6.1;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10.6;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Windows NT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1',
            'Mozilla/5.0 (Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
            'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
            'Mozilla/5.0 (Macintosh;U;IntelMacOSX10_6_8;en-us)AppleWebKit/534.50(KHTML,likeGecko)Version/5.1Safari/534.50',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.27 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/601.1.27',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
        ]
        # url = f'https://club.jd.com/productpage/p-{id}-s-3-t-5-p-0.html?callback=fetchJSON_comment98vv37'

        url = f'https://rate.tmall.com/list_detail_rate.htm?itemId=524673596684&spuId=473544268&sellerId=2594916711&order=3&currentPage=4&pageSize=20&append=0&picture=0'
        # else:
        #     url = f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId={id}&score=3&sortType=6&page={page}0&pageSize=10&isShadowSku=0&fold=1'
        headers = {
            'Accept': '*/*',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'User-Agent': random.choice(HEADERS),
            'Connection': 'keep-alive',
            # 'Host': 'club.jd.com',
        }
        # print(url)
        html = requests.get(url=url, headers=headers)
        print(html.text)
        # # 去掉多余得到json格式
        # content = html.text.strip('fetchJSON_comment98vv995();')
        # content = content.strip('fetchJSON_comment98vv37();')
        # json_flag = json.loads(content, strict=False)  # 收到的str内容进行清洗处理，变成可用的json，处理好了
        #
        # print('jdmain运行成功（京东爬虫主程序）')
        # JSONlist = json_flag["comments"]
        # if JSONlist == []:
        #     print('JDSpider评论为空')
        #     return [], [], '😅JDSpider爬虫评论为空'
        # commentList = []
        # imgList = []
        #
        # for num in range(0, len(JSONlist) - 1):
        #     if 'content' in JSONlist[num] and len(commentList) < 150000:  # 若存在内容，并且内容条数少于4条
        #         if len(JSONlist[num]['content']) <= 300 and len(JSONlist[num]['content']) >= 8:  # 控制字符150以内
        #             if '此用户未填写评' in JSONlist[num]['content'] \
        #                     or '垃圾' in JSONlist[num]['content'] \
        #                     or '不要买' in JSONlist[num]['content'] \
        #                     or '差评' in JSONlist[num]['content'] \
        #                     or '坏了' in JSONlist[num]['content'] \
        #                     or '刷' in JSONlist[num]['content'] \
        #                     or '评论' in JSONlist[num]['content'] \
        #                     or '别买' in JSONlist[num]['content'] \
        #                     or '后悔' in JSONlist[num]['content'] \
        #                     or '真烂' in JSONlist[num]['content'] \
        #                     or '寒心' in JSONlist[num]['content'] \
        #                     or '辣鸡' in JSONlist[num]['content'] \
        #                     or '差' in JSONlist[num]['content'] \
        #                     or '差' in JSONlist[num]['content'] \
        #                     or '慎重买' in JSONlist[num]['content'] \
        #                     or '投诉' in JSONlist[num]['content'] \
        #                     or '退货' in JSONlist[num]['content'] \
        #                     or '有缺陷' in JSONlist[num]['content'] \
        #                     or '不负责任' in JSONlist[num]['content'] \
        #                     or '**' in JSONlist[num]['content'] \
        #                     :
        #                 print('忽略内容--------------------------------------------')
        #                 pass
        #             else:
        #                 commentList.append(JSONlist[num]['content'].replace('\n', '').replace('\r', ''))
        #         else:
        #             continue
        # for num in range(0, len(JSONlist) - 1):
        #     if 'images' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
        #         for imgNum in range(0, len(JSONlist[num]['images'])):
        #             if 'imgUrl' in JSONlist[num]['images'][imgNum]:  # 控制字符150以内
        #                 this_imgUrl = JSONlist[num]['images'][imgNum]['imgUrl']
        #                 # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
        #                 if 'img30.360buyimg.com/n0/' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
        #                                                       "img30.360buyimg.com/n1/")
        #                 if 's128x96_jfs/' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
        #                 if '\n' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace('\n', '')
        #                 if '\r' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace('\r', '')
        #                 # if '//' in this_imgUrl:
        #                 #     this_imgUrl = this_imgUrl.replace("//", "")
        #                 imgList.append(this_imgUrl)
        #                 del this_imgUrl  # 销毁变量
        #             else:
        #                 continue
        #     if 'afterImages' in JSONlist[num] and len(imgList) < 10000:  # 若存在内容，并且内容条数少于4条
        #         print(JSONlist[num]['afterImages'])
        #         for imgNum in range(0, len(JSONlist[num]['afterImages'])):
        #             print(JSONlist[num]['afterImages'][imgNum])
        #             if 'imgUrl' in JSONlist[num]['afterImages'][imgNum]:  # 控制字符150以内
        #                 this_imgUrl = JSONlist[num]['afterImages'][imgNum]['imgUrl']
        #                 print(JSONlist[num]['afterImages'][imgNum]['imgUrl'])
        #                 # url统一修改函数：把里边的n0字符串替换，尺寸也替换掉 改成s720x540
        #                 if 'img30.360buyimg.com/n0/' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace("img30.360buyimg.com/n0/",
        #                                                       "img30.360buyimg.com/n1/")
        #                 if 's128x96_jfs/' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace("s128x96_jfs/", "s720x540_jfs/")
        #                 if '\n' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace('\n', '')
        #                 if '\r' in this_imgUrl:
        #                     this_imgUrl = this_imgUrl.replace('\r', '')
        #                 # if '//' in this_imgUrl:
        #                 #     this_imgUrl = this_imgUrl.replace("//", "")
        #                 imgList.append(this_imgUrl)
        #                 del this_imgUrl  # 销毁变量
        #             else:
        #                 continue
        #     else:
        #         continue
        #
        # print(f'京东爬虫程序结束,获取评论{len(commentList)}条，图片{len(imgList)}条')
        # # print(imgList)
        # random.shuffle(commentList)
        # random.shuffle(imgList)
        # # print(imgList)
        #
        # del content,json_flag,JSONlist
        # return commentList, imgList, '😆jdmain转换正常'  # 打乱重拍
        # # except Exception as e:
        # #     return [], [], '😅jdmain转换出错'


if __name__ == '__main__':
    # JDSpider().spider_comment(100016086218, 0)
    JDSpider().spider_itemData(100016086218)
    # TBSpider().spider_comment(100016086218, 0)
